<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <father></father>
  </div>
  <script src="./vue.js"></script>
  <script>
    const Child = {
      template:`
        <div>
          <h2>子组件</h2>
          <button @click="biubiu">发射</button>
        </div>
      `,
      data(){
        return {
          msg: '子组件的数据'
        }
      },
      methods: {
        biubiu(){
          // 触发子组件的自定义事件 名 piupiupiu 携带参数 this.msg
          this.$emit('piupiupiu', this.msg);
        }
      }
    }
    const Father = {
      template: `
        <div>
          <h1>这是父组件</h1>   
          {{ msg }}     
          <hr/>
          <child @piupiupiu="fn"></child>
        </div>
      `,
      data(){
        return {
          msg: ''
        }
      },
      methods: {
        fn(msg){
          console.log('我收到了', msg);
          this.msg = msg;
        }
      },
      components: {
        Child
      }
    };
    Vue.component('Father', Father)
    const vm = new Vue({
      el: '#app'
    })
  </script>
</body>
</html>